/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.javanile.me.chessengine;

/**
 *
 * @author cicciodarkast
 */
public class Move {
	
    private char	p;
    private char	c;
    private int		f;
	private int		t;
	private int		k;
	private int		e;
	private int		g;
	private char	w; // Promoted piece;
	
	public Move(char piece, int from, int to) {
		this(piece,from,to,'.',0,0,0,(char)0);
	}
	
	public Move(char piece, 
				int from, 
				int to, 
				char captured, 
				int kind, 
				int enpassant, 
				int castling,
				char promotion
			) {
		p = piece;
		f = from;
		t = to;
		c = captured;
		k = kind;
		e = enpassant;
		g = castling;
		w = promotion;
	}
	
	public Move() {
		this("e2e4");
	}
	
    public Move(String m) {
        f = Square.toInt(m.substring(0, 2));
        t = Square.toInt(m.substring(2, 4));
        k = Constants.MK_SIMPLE;        
    }
	
    public Move(char piece, Square from, Square to) {
        p = piece;
        //f = from;
        //t = to;
        k = 0;
    }
	
    public Move(char p, Square f, Square t,char c,int k) {
        this.p = p;
        //from = f;
        //to = t;
        this.c = c;
        this.k = k;
    }
	
    public Move(char p, Square f, Square t,char c) {
        this.p = p;
        //from = f;
        //to = t;
        this.c = c;
        k = 0;
    }
    
    public int getKind() {
        return k;
    }
    public int getFrom() {
        return f;
    }
    public int getTo() {
        return t;
    }       
	public char getPiece() {
		return p;
	}
    public char getCaptured() {
		return c;
	}
	public int getEnpassantStatus() {
		return e;
	}
	public int getCastlingStatus() {
		return g;
	}
	
	
	public boolean in(Moves moves) {
		if (moves.have(this)) {
			
			return true;
		}
		return false;
	}
	
	public boolean equals(Move m) {
		return (m.getFrom()==this.getFrom())&&(m.getTo()==this.getTo());
	}    
	
    public String toString() {
		String output = "";
		if (k==Constants.MK_SHORT_CASTLING) {
			output = Square.toString(f)+Square.toString(t);
		} else {
			output = Square.toString(f)+Square.toString(t);        
		}	
		if (w>0) output+="="+(w);
        return output;
    }
}
